using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Sudoku.StateManagement;
using Services;


namespace Sudoku.Menu
{
	public class LogoScreen : DrawableGameComponent
	{
		SpriteBatch sprite_batch;

		Texture2D logo;
		Rectangle texture_rectangle;
		Matrix screen_transform;
		float alpha;
		bool first;

		#region Constructors

		public LogoScreen(Game game)
			: base(game)
		{
			alpha = 0.0f;
			first = true;
		}

		#endregion

		protected override void LoadContent()
		{
			sprite_batch = new SpriteBatch(GraphicsDevice);
			screen_transform = Matrix.Identity;

			TextureLibrary textureService = Game.Services.GetService(typeof(TextureLibrary)) as TextureLibrary;

			logo = textureService.Logo("VST");
			texture_rectangle = new Rectangle((int)((Game.GraphicsDevice.Viewport.Width * 0.5f) - 150), (int)((Game.GraphicsDevice.Viewport.Height * 0.5f) - 58.5f), 300, 117);

			base.LoadContent();
		}

		public override void Update(GameTime gameTime)
		{
			float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

			alpha += dt;

			if (alpha > 2.0f)
			{
				if (first)
				{
					TextureLibrary textureService = Game.Services.GetService(typeof(TextureLibrary)) as TextureLibrary;
					logo = textureService.Logo("BoredSnail");
					texture_rectangle = new Rectangle((int)((Game.GraphicsDevice.Viewport.Width * 0.5f) - 128), (int)((Game.GraphicsDevice.Viewport.Height * 0.5f) - 128), 256, 256);
					alpha = 0.0f;
					first = false;
				}
				else Game.StartMenu();

			} 

			base.Update(gameTime);
		}

		public override void Draw(GameTime gameTime)
		{
			GraphicsDevice.Clear(Color.Black);

			sprite_batch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, screen_transform);

			sprite_batch.Draw(logo, texture_rectangle, Color.White * alpha);

			sprite_batch.End();

			base.Draw(gameTime);
		}
	}
}
